home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: Philippe Verdy <100105.3120@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: merge sort
- Date: 2 Apr 1996 00:01:52 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4jpqpg$lhj@dub-news-svc-6.compuserve.com>
- NNTP-Posting-Host: ad15-078.compuserve.com
-
- PC Lab User <lab-mail@cs.utas.edu.au> s'Θcrit :
- > has anyone got some source for the "merge" algorithm used in mergesort?
- > thanx
- >
- > m_wookey@postoffice.utas.edu.au
- This sort algorithm is of the same general idea as the QuickSort:
- Divide and conquer. It is dividing a segment to sort, into two
- subsegments to sort.
-
- With QuickSort: divide a segment in two parts, one for
- the keys below a given key, the other for all the keys
- higher than the same key. This key is called the pivot.
- The difficulty is to create this partition efficiently,
- so that minimum swaps occur. This is harder when you want
- this partition to be stable (i.e. keeping the relative
- order of equal keys) because it involves sliding groups
- of keys during the partition. There is in all cases no
- final step after the recursive calls.
-
- With merge sort, you don't choose a pivot, but divide the
- segment in two arbitrary subsegments, then call merge sort
- recursively on each of them.
- Once this is done, you have to merge these two segments
- The difficulty resides in this merging operation if you
- only have one medium to store them: This involves sliding
- groups of elements. But in all cases, this sort is stable
- and easier to understand.
-
-